package com.meituan.catering.management.order.utils;

import com.google.common.collect.Maps;
import com.meituan.catering.management.order.api.http.model.request.PlaceCateringOrderHttpRequest;
import com.meituan.catering.management.order.biz.model.request.AdjustCateringOrderBizRequest;
import com.meituan.catering.management.order.biz.model.request.PlaceCateringOrderBizRequest;
import com.meituan.catering.management.order.dao.model.CateringOrderItemDO;
import com.meituan.catering.management.order.remote.model.response.ProductDetailRemoteResponse;

import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @author Believe
 * Date 2022/6/1 10:53
 */
public class CateringOrderUtils {
    public static Set<Long> getIds(List<PlaceCateringOrderBizRequest.Item> itemList) {
        Set<Long> ids = new HashSet<>();
        for (PlaceCateringOrderBizRequest.Item item : itemList) {
            ids.add(item.getProductId());
        }
        return ids;
    }

    public static Set<Long> getHttpIds(List<PlaceCateringOrderHttpRequest.Item> itemList) {
        Set<Long> ids = new HashSet<>();
        for (PlaceCateringOrderHttpRequest.Item item : itemList) {
            ids.add(item.getProductId());
        }
        return ids;
    }

    public static Set<Long> getAdjustIds(List<AdjustCateringOrderBizRequest.Item> itemList) {
        Set<Long> ids = new HashSet<>();
        for (AdjustCateringOrderBizRequest.Item item : itemList) {
            ids.add(item.getProductId());
        }
        return ids;
    }

    public static Set<Long> getItemDOIds(List<CateringOrderItemDO> cateringOrderItemDOList) {
        Set<Long> ids = new HashSet<>();
        for (CateringOrderItemDO item : cateringOrderItemDOList) {
            ids.add(item.getId());
        }
        return ids;
    }

    public static Map<Long, ProductDetailRemoteResponse> groupById(List<ProductDetailRemoteResponse> productThriftList) {
        Map<Long, ProductDetailRemoteResponse> productMap = Maps.newHashMap();
        for (ProductDetailRemoteResponse productDetailRemoteResponse : productThriftList) {
            if (!productMap.containsKey(productDetailRemoteResponse.getId())) {
                productMap.put(productDetailRemoteResponse.getId(), productDetailRemoteResponse);
            }
        }
        return productMap;
    }
}
